package com.hethongviet.job.helpers;

import com.hethongviet.job.models.Tab;

import android.view.View;
import android.view.View.OnClickListener;

public class TabMenu
{
	private int _buttonResource = -1;
	private int _buttonResourceHighlight = -1;
	private boolean[] _isActiveButtons = null;
	private Tab[] _arrayTabs = null;
	private int _numberButtons = 0;
	private int _currentButtonActive = 0;

	public TabMenu()
	{
	}

	/**
	 * 
	 * @param arrayButtons
	 *            is not null
	 * @param buttonResource
	 * @param buttonResourceHighlight
	 */
	public TabMenu(Tab[] arrayTabs, int buttonResource,
			int buttonResourceHighlight)
	{
		_buttonResource = buttonResource;
		_buttonResourceHighlight = buttonResourceHighlight;
		_arrayTabs = arrayTabs;

		_isActiveButtons = new boolean[_numberButtons = arrayTabs.length];
		_isActiveButtons[0] = true;

		for (int i = 0; i < _numberButtons; i++)
		{
			if (i != 0)
				_isActiveButtons[i] = false;
			final int i1 = i;
			arrayTabs[i].getButton().setOnClickListener(new OnClickListener() {
				public void onClick(View arg0)
				{
					moveToTab(i1);
				}
			});
		}
	}

	public int getCurrentButtonActive()
	{
		return _currentButtonActive;
	}

	public void moveToTab(int tabIndex)
	{
		if (_currentButtonActive != tabIndex)
		{
			/* Reset the old button */
			_isActiveButtons[_currentButtonActive] = false;
			_arrayTabs[_currentButtonActive].getButton().setBackgroundResource(_buttonResource);
			_arrayTabs[_currentButtonActive].getButton().setTextSize(10);
			_arrayTabs[_currentButtonActive].getLinearLayout().setVisibility(View.GONE);
			/* Reset current tab */
			_currentButtonActive = tabIndex;
			/* Update the new button */
			_isActiveButtons[_currentButtonActive] = true;
			_arrayTabs[_currentButtonActive].getButton().setBackgroundResource(_buttonResourceHighlight);
			_arrayTabs[_currentButtonActive].getButton().setTextSize(11);
			_arrayTabs[_currentButtonActive].getLinearLayout().setVisibility(View.VISIBLE);
		}
	}

}
